/**
 * 
 */
package ac.rfr.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTabbedPane;
import javax.swing.JToolBar;

/**
 * @author Enigmanic
 *
 */
public class MainWindow extends JFrame {
	
	public interface ExportedComponents{
		public static final String MW_TOOLBAR 			= "MW_TOOLBAR";
		public static final String MW_STATUS_BAR		= "MW_STATUS_BAR";
		
		public static final String MW_ACTION_MENU	= "MW_ACTION_MENU";
		public static final String MW_HELP_MENU			= "MW_HELP_MENU";
		
		public static final String MW_EXIT_MI					= "MW_EXIT_MI";
		public static final String MW_RELOAD_MI			= "MW_RELOAD_MI";
		public static final String MW_OPEN_MI				= "MW_OPEN_MI";
		public static final String MW_OPEN_TEMP_MI	= "MW_OPEN_TEMP_MI";
		public static final String MW_HELP_MI				= "MW_HELP_MI";
		
		
		public static final String MW_TABBED_PANE		= "MW_TABBED_PANE";
		
		public static final String MW_MAIN_WINDOW  = "MW_MAIN_WINDOW";
		
		public static final String MW_STATUS_LABEL		= "MW_STATUS_LABEL";
		public static final String MW_RELOAD_BUTTON	= "MW_RELOAD_BUTTON";
	}
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final String WINDOW_TITLE = "Recording File Reader";
	
	private JLabel statusLabel;
	private JToolBar statusBar, toolBar;
	private JMenuBar menuBar ;
	private JMenuItem openMI, reloadMenu, exitMI, helpMI,openTemplateMI;
	private JMenu actionMenu, helpMenu;
	private JButton refreshButton;
	private JTabbedPane tabbedPane;

	public MainWindow() {
		super(WINDOW_TITLE);
		initComponents();
		setLocation();
		exportComponents();
	}

	private void initComponents() {
		getContentPane().setLayout(new BorderLayout(0, 0));

		statusBar = new JToolBar();
		getContentPane().add(statusBar, BorderLayout.SOUTH);

		statusLabel = new JLabel("Status");
		statusBar.add(statusLabel);

		toolBar = new JToolBar();
		getContentPane().add(toolBar, BorderLayout.NORTH);

		refreshButton = new JButton("Refresh");
		toolBar.add(refreshButton);

		menuBar = new JMenuBar();
		setJMenuBar(menuBar);

		actionMenu = new JMenu("Action");
		menuBar.add(actionMenu);

		openMI = new JMenuItem("Open");
		actionMenu.add(openMI);
		
		openTemplateMI = new JMenuItem("Open Template");
		actionMenu.add(openTemplateMI);

		reloadMenu = new JMenuItem("Reload");
		actionMenu.add(reloadMenu);

		exitMI = new JMenuItem("Exit");
		actionMenu.add(exitMI);

		helpMenu = new JMenu("Help");
		menuBar.add(helpMenu);

		helpMI = new JMenuItem("Help");
		helpMenu.add(helpMI);
		
		tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		getContentPane().add(tabbedPane,BorderLayout.CENTER);

	}

	public void setLocation()
	{
		Dimension	 scrSize = Toolkit.getDefaultToolkit().getScreenSize();
		setSize((int)((scrSize.getWidth()*3)/4),(int)((scrSize.getHeight()*3)/4));
		setLocation((int)(scrSize.getWidth()/2 - getWidth()/2),(int)(scrSize.getHeight()/2 - getHeight()/2)); 
	}
	
	
	public void setTitle(String title)
	{
		setTitle(WINDOW_TITLE + "-" + title);
	}

	public JMenuItem getOpenMI() {
		return openMI;
	}

	public JMenuItem getReloadMenu() {
		return reloadMenu;
	}

	public JMenuItem getExitMI() {
		return exitMI;
	}

	public JMenuItem getHelpMI() {
		return helpMI;
	}

	public JButton getRefreshButton() {
		return refreshButton;
	}

	public JLabel getStatusLabel() {
		return statusLabel;
	}

	public JToolBar getStatusBar() {
		return statusBar;
	}

	public JToolBar getToolBar() {
		return toolBar;
	}
	
	private void exportComponents()
	{
		UIComponentLibrary.addComponent(ExportedComponents.MW_ACTION_MENU,actionMenu);
		UIComponentLibrary.addComponent(ExportedComponents.MW_EXIT_MI,exitMI);
		UIComponentLibrary.addComponent(ExportedComponents.MW_HELP_MENU,helpMenu);
		UIComponentLibrary.addComponent(ExportedComponents.MW_HELP_MI,helpMI);
		UIComponentLibrary.addComponent(ExportedComponents.MW_MAIN_WINDOW,this);
		UIComponentLibrary.addComponent(ExportedComponents.MW_OPEN_MI,openMI);
		UIComponentLibrary.addComponent(ExportedComponents.MW_RELOAD_MI,reloadMenu);
		UIComponentLibrary.addComponent(ExportedComponents.MW_STATUS_BAR,statusBar);
		UIComponentLibrary.addComponent(ExportedComponents.MW_TABBED_PANE,tabbedPane);
		UIComponentLibrary.addComponent(ExportedComponents.MW_TOOLBAR,toolBar);
		UIComponentLibrary.addComponent(ExportedComponents.MW_STATUS_LABEL,statusLabel);
		UIComponentLibrary.addComponent(ExportedComponents.MW_RELOAD_BUTTON,refreshButton);
	}
	
	public static void main(String args[])
	{
		MainWindow mainWindow = new MainWindow();
		mainWindow.setVisible(true);
	}

	public JMenuItem getOpenTemplateMI() {
		return openTemplateMI;
	}
	
}
